//
//  CenterViewController.m
//  Flava
//
//  Created by Ug-Code on 13-8-12.
//  Copyright (c) 2013年 UgCode. All rights reserved.
//

#import "CenterViewController.h"
#import "NavLeftButton.h"
#import "AddContentViewController.h"


@interface CenterViewController ()

/** 创建NavBar */
- (void)createNavigationBar;
/** 创建用户头像 */
- (void)createAvatarsView;
/** 创建navigationBar Left按钮 */
- (void)createLeftButton;
/** 创建navigationBar Add按钮 */
- (void)createAddButton;
/** 创建时间轴图片 */
- (void)createTimelineImage;

@end

@implementation CenterViewController

@synthesize
avatarsView = _avatarsView,
navigationBar = _navigationBar;

- (void)viewDidLoad
{
    [super viewDidLoad];
	
	[self createNavigationBar];
	[self createAvatarsView];
	[self createLoadingView];
	[self createLeftButton];
	[self createTimelineImage];
	[self createAddButton];
	//临时背景颜色
	self.view.backgroundColor = [UIColor grayColor];
	self.viewDeckController.leftSize = 60;	//左侧视图中右侧被遮盖的部分
	
}


- (void)startLoading
{
	static BOOL isLoading = NO;
	if ((isLoading = !isLoading)) {
		[_loadingView startAnimation];
	} else {
		[_loadingView stopAnimation];
	}
}

/** 打开添加内容页面 */
- (void)pushAddContentView
{
	AddContentViewController *addContentVC = [[AddContentViewController alloc] init];
	[self.navigationController pushViewController:addContentVC animated:YES];
}

/** 创建NavBar */
- (void)createNavigationBar
{
//	self.view.backgroundColor = [UIColor greenColor];
	[self.navigationController setNavigationBarHidden:YES]; //隐藏自带的navigationBar
	_navigationBar = [[NavigationBar alloc] init];
	_navigationBar.shadow = YES;
	[self.view addSubview:_navigationBar];
}

/** 创建用户头像 */
- (void)createAvatarsView
{
	_avatarsView = [AvatarsView navRoundAvatarsView];
	self.navigationBar.titleView = _avatarsView;
}

/** 创建navigationBar Left按钮 */
- (void)createLeftButton
{
	NavLeftButton *leftButton = [[NavLeftButton alloc] init];
	[self.navigationBar addSubview:leftButton];
	[leftButton addTarget:self.viewDeckController
				   action:@selector(toggleLeftView)
		 forControlEvents:UIControlEventTouchUpInside];
}

/** 创建navigationBar Add按钮 */
- (void)createAddButton
{
	NavAddButton *addButton = [[NavAddButton alloc] init];
	[self.navigationBar addSubview:addButton];
	[addButton addTarget:self action:@selector(pushAddContentView) forControlEvents:UIControlEventTouchUpInside];
}

/** 创建时间轴图片 */
- (void)createTimelineImage
{
	UIImageView *imageView = [[UIImageView alloc]
							  initWithImage:[UIImage imageNamed:@"navigation_bar_timeline.png"]];
	imageView.frame = CGRectMake(299, 18, 7, 26);
	[self.navigationBar addSubview:imageView];
}

/** 创建页面加载图标 */
- (void)createLoadingView
{
	_loadingView = [[NetLoadingView alloc] init];
	_loadingView.center = CGPointMake(320/2, 44/2);
	[self.navigationBar addSubview:_loadingView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated
{
//	[self.viewDeckController openLeftViewAnimated:YES];	//自动滑倒Left页面
//	NSLog(@"viewDidAppear");
}

- (void)viewWillAppear:(BOOL)animated
{
//	NSLog(@"viewWillAppear");
}
//
//- (void)viewWillDisappear:(BOOL)animated
//{
//	NSLog(@"viewWillDisappear");
//}
//
//- (void)viewDidDisappear:(BOOL)animated
//{
//	NSLog(@"viewDidDisappear");
//}

@end
